const WebpackDevServer = require('webpack-dev-server');
const webpack = require('webpack');

const devWebpackConfig = require('./config/webpack.dev');
const prodWebpackConfig = require('./config/webpack.prod');
const build = ()=>{
    const compiler = webpack(prodWebpackConfig);
    compiler.run((err, res) => {
      if(err){
  
        console.log('打包', err, res);
      }else{
        console.log('build success...',err);
      }
    })
}
const dev = ()=>{
    const compiler = webpack(devWebpackConfig);
    const devServerOptions = { ...devWebpackConfig.devServer};
    const server = new WebpackDevServer(devServerOptions, compiler);
  
    const runServer = async () => {
      console.log('Starting server...');
      await server.start();
    };
    runServer();
}
module.exports = {
    build,
    dev
}